﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ANLP.Parser
{
    public enum GoToType
    {
        State,
        Rule,
        Token,
    }

    internal class GoToExpression
    {
        public GoToExpression(string stateName, GoToType gotoType)
            : this(stateName, -1, gotoType)
        {
        }

        public GoToExpression(string stateName, int ruleId, GoToType gotoType)
        {
            StateName = stateName;
            RuleIndex = ruleId;
            RuleTargetsIndex = new List<GoToExpression>();
            type = gotoType;
            actions = new Dictionary<int, CodeExpression>();
        }

        Dictionary<int, CodeExpression> actions;

        public void AddAction(int step, CodeExpression code)
        {
            actions.Add(step, code);
        }

        private GoToType type;

        public GoToType Type
        {
            get
            {
                if (source == null)
                    return type;
                return source.Type;
            }
        }

        public string StateName { get; set; }

        private int ruleIndex;

        public int RuleIndex
        {
            get
            {
                if (source != null)
                    return source.RuleIndex;
                return ruleIndex;
            }
            set { ruleIndex = value; }
        }

        public List<GoToExpression> RuleTargetsIndex { get; private set; }

        private GoToExpression source;

        internal void ChangeNature(GoToExpression goToExpression)
        {
            source = goToExpression;
        }

        public IDictionary<int, CodeExpression> Actions { get { return actions; } }
    }
}
